home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: const usage as #define
- Date: 17 Feb 1996 22:55:44 GMT
- Organization: Borland International
- Distribution: ca
- Message-ID: <4g5mdg$m25@druid.borland.com>
- References: <4frc93$2s8@fmsu03.fm.intel.com>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4frc93$2s8@fmsu03.fm.intel.com>, tomtzigt@frx215.intel.com says...
- >
- >We are trying to port a piece of C++ code to different platforms.
- >The code was developed with GNU g++, but we would like to use
- >the native compilers that come with the different platforms.
- >On IBM we use c++, on HP we use cfront, and on NT we use VC++.
- >Now the following situation arises: given this piece of code
- >
- >class foo {
- > private:
- > const int SIZE = 10;
- > int array[SIZE];
- > public:
- > foo();
- >};
- >
-
- I don't use GNU, so I assume this is a gnu extension. There's been a similar
- change to the language definition recently, so that you can initialize static
- const integral types directly in the class definition. Like this:
-
- class foo
- {
- static const int size = 10;
- int array[size];
- };
-
- const int foo::size; // no initialization allowed here: we already did it
-
- You can still use the other style, with no initializer in the class definition
- and an explicit initializer in the definition of size. The value of size would
- not be a compile-time constant, so if you did that you couldn't use it as the
- size of an array.
- -- Pete
-
-